<?php
namespace app\merchant\controller\app;
use app\common\controller\BaseController;
use app\common\service\app\MerchantBlacklistService;
use app\common\validate\app\MerchantBlacklistValidate;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("买家黑名单")
 * @Apidoc\Group("app")
 * @Apidoc\Sort("250")
 */
class MerchantBlacklist extends BaseController
{
    /**
    * @Apidoc\Title("买家黑名单列表")
    * @Apidoc\Query(ref="pagingQuery")
    * @Apidoc\Query(ref="sortQuery")
    * @Apidoc\Query(ref="searchQuery")
    * @Apidoc\Query(ref="dateQuery")
    * @Apidoc\Returned(ref="expsReturn")
    * @Apidoc\Returned(ref="pagingReturn")
    * @Apidoc\Returned("list", type="array", desc="买家黑名单列表", children={
    *   @Apidoc\Returned(ref="app\common\model\MerchantBlacklistModel", field="id,title,content,is_disable,create_time,update_time,store_platform_id,member_id,member_account_id,block_remark")
    * })
    */
    public function list()
    {
        $where = $this->buildWhere([
            'store_platform_id'
        ]);
        $where = $this->where(where_delete($where));
        $where[] = ['mer_id','=',mer_id()];
        $data = MerchantBlacklistService::list($where, $this->page(), $this->limit(), $this->order());
        return success($data);
    }
    /**
    * @Apidoc\Title("买家黑名单信息")
    * @Apidoc\Query(ref="app\common\model\MerchantBlacklistModel", field="id")
    * @Apidoc\Returned(ref="app\common\model\MerchantBlacklistModel")
    */
    public function info()
    {
        $param = $this->params(['id/d' => '']);
        validate(MerchantBlacklistValidate::class)->scene('info')->check($param);
        $data = MerchantBlacklistService::info($param['id']);
        return success($data);
    }
    /**
    * @Apidoc\Title("买家黑名单添加")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantBlacklistModel", field="title,content,is_disable,store_platform_id,member_id,member_account_id,block_remark")
    */
    public function add()
    {
        $param = $this->params(MerchantBlacklistService::$edit_field);
        validate(MerchantBlacklistValidate::class)->scene('add')->check($param);
        $param['mer_id'] = mer_id();
        $data = MerchantBlacklistService::add($param);
        return success($data);
    }
    /**
    * @Apidoc\Title("买家黑名单修改")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="app\common\model\MerchantBlacklistModel", field="id,title,content,is_disable,store_platform_id,member_id,member_account_id,block_remark")
    */
    public function edit()
    {
        $param = $this->params(MerchantBlacklistService::$edit_field);
        validate(MerchantBlacklistValidate::class)->scene('edit')->check($param);
        $data = MerchantBlacklistService::edit($param['id'], $param);
        return success($data);
    }
    /**
    * @Apidoc\Title("买家黑名单删除")
    * @Apidoc\Method("POST")
    * @Apidoc\Param(ref="idsParam")
    */
    public function dele()
    {
        $param = $this->params(['ids/a' => []]);
        validate(MerchantBlacklistValidate::class)->scene('dele')->check($param);
        $data = MerchantBlacklistService::dele($param['ids']);
        return success($data);
    }
    /**
     * @Apidoc\Title("买家黑名单禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="idsParam")
     * @Apidoc\Param(ref="app\common\model\MerchantBlacklistModel", field="is_disable")
     */
    public function disable()
    {
        $param = $this->params(['ids/a' => [], 'is_disable/d' => 0]);
        validate(MerchantBlacklistValidate::class)->scene('disable')->check($param);
        $data = MerchantBlacklistService::edit($param['ids'], $param);
        return success($data);
    }
}
